package com.springapi.service.impl;

import com.springapi.entity.Orderev;
import com.springapi.dao.OrderevDao;
import com.springapi.service.OrderevService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 系统设置
实付金额=合计金额或vip合计金额 -折扣金额-生日金额-抹零金额(Orderev)表服务实现类
 *
 * @author makejava
 * @since 2025-01-07 08:37:55
 */
@Service("orderevService")
public class OrderevServiceImpl implements OrderevService {
    @Resource
    private OrderevDao orderevDao;

    @Override
    public Double getcountorderev(int appid, int shopid, Date createdate1, Date createdate2) {
        return orderevDao.getcountorderev(appid,shopid,createdate1,createdate2);
    }

    @Override
    public Double getsumpayamount(int appid, int shopid, Date createdate1, Date createdate2) {
        return orderevDao.getsumpayamount(appid,shopid,createdate1,createdate2);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Orderev queryById(Integer id) {
        return this.orderevDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param orderev 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Orderev> queryByPage(Orderev orderev, PageRequest pageRequest) {
        long total = this.orderevDao.count(orderev);
        return new PageImpl<>(this.orderevDao.queryAllByLimit(orderev, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderev 实例对象
     * @return 实例对象
     */
    @Override
    public Orderev insert(Orderev orderev) {
        this.orderevDao.insert(orderev);
        return orderev;
    }

    /**
     * 修改数据
     *
     * @param orderev 实例对象
     * @return 实例对象
     */
    @Override
    public Orderev update(Orderev orderev) {
        this.orderevDao.update(orderev);
        return this.queryById(orderev.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.orderevDao.deleteById(id) > 0;
    }
}
